#include "main.h"
#include "motor_encoder.h"

void Encoder_Init()
{
	HAL_TIM_Encoder_Start(&htim2, TIM_CHANNEL_ALL);
	HAL_TIM_Encoder_Start(&htim4, TIM_CHANNEL_ALL);
}

int Read_Speed(TIM_HandleTypeDef *htim)
{
	int temp;
	temp=(short)__HAL_TIM_GetCounter(htim);
	__HAL_TIM_SetCounter(htim,0);  // clear
	return temp;
}

int Encoder_Get_Speed_Left(void)
{
	int speed;
	speed = Read_Speed(&htim2);
	return speed;
}

int Encoder_Get_Speed_Right(void)
{
	int speed;
	speed = Read_Speed(&htim4);
	return -speed;
}
